# Contributor: Hoang Nguyen <folliekazetani@protonmail.com>
maintainer="Hoang Nguyen <folliekazetani@protonmail.com>"
pkgname=helmfile
pkgver=0.169.0
pkgrel=0
pkgdesc="Declarative spec for deploying helm charts"
url="https://helmfile.readthedocs.io/"
# armhf: ftbfs
arch="all !armhf"
license="MIT"
depends="helm"
makedepends="go"
checkdepends="bash"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-zsh-completion
	$pkgname-fish-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/helmfile/helmfile/archive/refs/tags/v$pkgver.tar.gz"
options="net" # download Go modules

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	local _goldflags="
	-X go.szostok.io/version.version=$pkgver
	-X go.szostok.io/version.buildDate=$(date -u "+%Y-%m-%dT%H:%M:%S%z" ${SOURCE_DATE_EPOCH:+-d @$SOURCE_DATE_EPOCH})
	-X go.szostok.io/version.commitDate=$(date -u "+%Y-%m-%dT%H:%M:%S%z" ${SOURCE_DATE_EPOCH:+-d @$SOURCE_DATE_EPOCH})
	-X go.szostok.io/version.commit=0000000
	-X go.szostok.io/version.dirtyBuild=false
	-X github.com/helmfile/helmfile/pkg/runtime.v1Mode=true
	"
	go build -v -o helmfile -ldflags "$_goldflags"

	for shell in bash fish zsh; do
		./helmfile completion $shell > $pkgname.$shell
	done
}

check() {
	# /test/e2e/template/helmfile module relies on external binaries and helm plugins only available for x86_64
	# shellcheck disable=2046
	go test $(go list ./... | grep -v /e2e)
}

package() {
	install -Dm755 $pkgname "$pkgdir"/usr/bin/$pkgname
	install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/

	install -Dm644 helmfile.bash \
		"$pkgdir"/usr/share/bash-completion/completions/helmfile
	install -Dm644 helmfile.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_helmfile
	install -Dm644 helmfile.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/helmfile.fish
}

sha512sums="
bee9c79e52a2526a5c03ef994d2e951ad81a503d812bc380910e390c7bc42a2b46a255419896a04f8b9d1915c47d64ded2611598fbeaf07e94d506c64f12f848  helmfile-0.169.0.tar.gz
"
